#ifndef VIZULIZATOR_H
#define VIZULIZATOR_H

#include <QGLWidget>
#include <QMouseEvent>
#include <QGLShaderProgram>
#include <QGLFramebufferObject>
#include "modeldata.h"
#include "camera.h"
#include "light.h"
#include "ship.h"
#include "water.h"
#include "mathbox.h"

class Vizulizator : public QGLWidget
{
	Q_OBJECT

public:
	Vizulizator(QWidget *parent = 0);
	~Vizulizator();

	QSize minimumSizeHint() const;
    QSize sizeHint() const;
	int heightForWidth (int w) const;

public slots:
     void setShipRenderData(const ShipRenderData& shipRenderData);

protected:
	void initializeGL();
	void paintGL();
	void resizeGL(int width, int height);
	void mousePressEvent(QMouseEvent *e);
	void mouseMoveEvent(QMouseEvent *e);
	void wheelEvent(QWheelEvent *e);
	void keyPressEvent(QKeyEvent *e);
	void timerEvent(QTimerEvent *e);

private:
	void CreateShadowTex(const int width, const int height, GLuint& shadowMap);
	void GenerateShadowTex(const int width, const int height, const float* projection, const float* modelView, GLuint& shadowMap);
	void ApplyShadowTex(const GLenum texNum, GLuint shadowMap, const float* projection, const float* modelView);

private:
	QPoint lastPos;
	GLuint shadowMap;
	GLsizei shadowTexX;
	GLsizei shadowTexY;
	ShipRenderData shipRenderData;

	Camera* camera;
	Light* light;
	Ship* ship;
	Water* water;
};

#endif // VIZULIZATOR_H
